<template>
	<div class="app-container">
		<div class="zd3">
			<div class="zd3-title">
				<p>
					<span>姓名</span>
					<input v-model="username" type="text" placeholder="请输入姓名" />
				</p>
				<p>
					<span>职务</span>
					<input v-model="workname" type="text" placeholder="请输入职务" />
				</p>
				<p>
					<span>手机号</span>
					<input v-model="userphone" type="text" placeholder="请输入手机号" />
				</p>
				<h3 @click="getList">查询</h3>
        <h4 @click="resetList">重置</h4>
				<h3 @click="addPeo" style="background: #0093FF">新增</h3>
			</div>
			<div class="files">
				<div class="files-left">
					<el-menu class="el-menu-vertical-demo" :default-active="activeIndex">
						<el-submenu index="1" v-for="(item,index) in ifydata" :index="index" :key="'id'+index">
							<template slot="title"><span>{{item.companyName}}</span></template>
							<el-menu-item v-for="(item1,index1) in item.departmentsList" @click="changeDeparment(item1)" :index="index1" :key="'id'+index1">
								<span slot="title">{{item1.departments}}</span>
							</el-menu-item>
						</el-submenu>
					</el-menu>
				</div>
				<div class="files-right">
					<div class="files-btm">
						<el-table :data="peopleData" height="500" style="margin-bottom: 20px;" :show-header="true" v-loading="loading">
							<!-- <el-table-column align="center" prop="code" label="编码"></el-table-column> -->
							<el-table-column align="center" label="头像" width="100">
								<template slot-scope="scope">
									<img :src="scope.row.icon" alt="" class="avatar">
								</template>
							</el-table-column>
							<el-table-column align="center" prop="username" label="姓名"></el-table-column>
							<el-table-column align="center" prop="departments" label="所属部门"></el-table-column>
							<el-table-column align="center" prop="sex" width="80" label="性别"></el-table-column>
							<el-table-column align="center" prop="power" label="职务"></el-table-column>
							<el-table-column align="center" prop="phone" width="120" label="手机号码"></el-table-column>
							<el-table-column align="center" prop="email" width="180" label="邮箱"></el-table-column>
							<!-- <el-table-column align="center" prop="status" label="状态"></el-table-column> -->
							<el-table-column align="center" width="200" label="操作" fixed="right">
								<template slot-scope="scope">
									<el-button type="text" size="small" @click="look(scope.row)">查看</el-button>
									<el-button type="text" size="small" @click="write(scope.row, scope.$index)">修改</el-button>
									<el-popconfirm placement="top" hideIcon title="是否要删除此行？" @onConfirm="deleteRow(scope.row)">
										<el-button type="text" size="small" slot="reference">删除</el-button>
									</el-popconfirm>
								</template>
							</el-table-column>
						</el-table>
						<el-pagination background align='right' :page-size="50" layout="prev, pager, next" :total="total" @prev-click="goPrev" @next-click="goNext" @current-change="goPage" />
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
let navindex = null;
import { getUser,deleteUser,getBumen,getBumenNew } from '@/api/people'
export default {
	data() {
		return {
			username: '',  //用户名
			workname: '',  //职称
			userphone: '', //电话
			total: 1,
			pages: 1,
			showHeader: false,
			loading: true,
			activeIndex: -1,  //选中下标
			checkedId: '',
			peopleData: [],
			ifydata: [],
			dialogVisible: false,
			tempData: '',
			tempId: '',
			tempIndex: -1,
		};
	},
	mounted(){
		navindex = null
		// this.getList()
		this.getbumens()
  },
	methods: {
		getbumens(){
			getBumenNew({}).then(res => {
				console.log(res)
				res.data.map(item => {
					item.departmentsList.map(list => {
						list.value = item.departments
						return list
					})
					return item
				})
				this.ifydata = res.data
				const dep = this.$store.state.user.userInfo[0].departments
				const arg = {
					departments: dep
				}
				// this.activeIndex = res.data.findIndex(item => item.departments == dep)
				// console.log(this.activeIndex)
				// console.log(this.ifydata)
				this.changeDeparment(arg)
			})
		},
		getList(){
			this.loading = true
			const param = {
				username: this.username ? this.username : null,
				departments: navindex ? navindex : null,
				power: this.workname ? this.workname : null,
				phone: this.userphone ? this.userphone : null,
				currentPage: this.pages
			}
			getUser(param).then(res => {
				console.log(res)
				this.peopleData = res.data.list
				this.total = res.data.total
				this.loading = false
			})
		},
		// 更改之后切换导航
		changeDeparment(item){
			navindex = item.departments
			this.getList()
		},
		// 切换导航
		handleSelece(index){
			this.loading = true
			console.log(index)
			console.log(this.ifydata[index])
			navindex = this.ifydata[index].value
			console.log('navindex',navindex)
			this.getList()
		},
		look(item){
			this.$router.push({
				name:'Lookpersonnel',
				params: {
					options: JSON.stringify(item)
				}
			})
		},
		write(item, index) {
			this.$router.push({
				name: 'Writepersonnel',
				params: {
					options: JSON.stringify(item)
				}
			})
		},
		deleteRow(item) {
			console.log('删除');
			deleteUser(item.userId).then(res => {
				console.log(res)
				this.$message({
					showClose: true,
					message: res.message,
					type: 'success'
				})
				this.getList()
			}) 
		},
		goPrev(page) {
			console.log(page);
			this.pages--
			this.getList()
		},
		goNext(page) {
			console.log(page);
			this.pages++
			this.getList()
		},
		goPage(page){
			this.pages = page
			this.getList()
		},
		resetList() {
			this.username = ''
			this.workname = ''  //职称
			this.userphone = ''
			this.departments = ''
			// this.activeIndex = ''
			navindex = null
		},
		addPeo(item) {
			this.$router.push({name: 'Writepersonnel'})
		}
	}
};
</script>

<style lang="scss" scoped>
/deep/.el-button--primary {
	color: #fff;
	background-color: #18a05e !important;
	border-color: #18a05e !important;
}
/deep/.el-button--primary:hover,
.el-button--primary:focus {
	background: #18a05e !important;
	border-color: #18a05e !important;
	color: #fff !important;
}
/deep/.el-button:hover,
.el-button:focus {
	color: #18a05e;
	background-color: transparent;
}
/deep/.el-button--primary {
	color: #fff;
	background-color: #18a05e;
	border-color: #18a05e;
}
/deep/.el-button--text {
	color: #00c666 !important;
}


.app-container {
	padding: 15px;
}
.status {
	border-radius: 3px;
	font-size: 14px;
	width: 50px;
	color: #fff;
	background: #777777;
	margin: 0 auto;
}
.status-active {
	background: #18a05e;
}
.inps {
	width: 100%;
	height: 32px;
	line-height: 32px;
	padding-left: 10px;
	background: none;
	border: none;
	color: #333;
}
.inps-active {
	width: 100%;
	height: 32px;
	line-height: 32px;
	padding-left: 10px;
	// background:#ccc;
	border: none;
	color: #333;
}
.zd3-title {
	height: 80px;
	display: flex;
	align-items: center;
	padding: 0 20px;
	position: relative;
	background: #ffffff;
	border-radius: 8px;
	border: 1px solid rgba(0, 0, 0, 0.1);

	> p {
		font-size: 14px;
		color: #333;
		margin-right: 20px;

		> span {
			padding-right: 5px;
		}

		> input {
			width: 170px;
			height: 32px;
			// background: #ccc;
			border-radius: 3px;
			border: 1px solid #ccc;
			padding-left: 10px;
			color: #333;
		}
	}

	> h3 {
		width: 64px;
		height: 32px;
		background: #18a05e;
		border-radius: 3px;
		margin: 0 30px 0 0;
		color: #fff;
		font-size: 14px;
		line-height: 32px;
		font-weight: 100;
		text-align: center;
		cursor: pointer;
	}

	> h4 {
		width: 64px;
		height: 32px;
		border-radius: 3px;
		border: 1px solid rgba(0, 0, 0, 0.1);
		color: #333;
		font-size: 14px;
		line-height: 32px;
		font-weight: 100;
		text-align: center;
		cursor: pointer;
		margin-right: 30px;
	}
}
.files {
	display: flex;
	background: #fff;
	border: 1px solid rgba(0, 0, 0, 0.1);
	border-radius: 8px;
	margin-top: 15px;
	overflow: hidden;
	padding: 15px 15px 15px 10px;
}
/deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #18a05e !important;
  color: #fff;
}
.files-btm /deep/.btn-prev:after {
  content: "上一页";
}
.files-btm /deep/.btn-next:before {
  content: "下一页";
}
.files-btm /deep/.btn-prev,
.files-btm /deep/.btn-next {
  width: 65px !important;
	display: inline-flex !important;
	align-items: center !important;
	justify-content: center !important;
}
.avatar{
	width: 30px;
	height: 30px;
}
.files-left {
	width: 270px;
	margin-right: 15px;
	height: 80vh;
	overflow-y: auto;
	/deep/.el-menu{
		border-right: none;
	}
	/deep/.el-menu-item{
		height: 35px;
		line-height: 35px;
		margin-bottom: 8px;
	}
	/deep/.el-menu-item.is-active{
		color: #fff;
		border-radius: 5px;
		background: rgba(24,160,94,.8);
	}
}
.files-right {
	flex: 1;
	overflow: hidden;
}
.files-btm {
	background: rgba(255, 255, 255, 1);
	border-radius: 8px;
	border: 1px solid rgba(0, 0, 0, 0.1);
	// margin-top: 20px;
	overflow: hidden;
	&-title {
		display: flex;
		align-items: center;
		height: 45px;
		border-bottom: 1px solid rgba(0, 0, 0, 0.1);
		background: #ffffff;
		> p {
			text-align: center;
			font-size: 14px;
			color: #333;
		}
	}
	.el-pagination {
		white-space: nowrap;
		padding: 15px 5px;
		color: #303133;
		font-weight: bold;
	}
	.addDate {
		margin: 20px 32px 10px 32px;
		height: 32px;
		border-radius: 3px;
		text-align: center;
		line-height: 32px;
		font-size: 14px;
		color: #333;
		cursor: pointer;
		border: 1px dashed rgba(0, 0, 0, 0.3);
	}
	.el-button--text {
		margin: 0 15px;
	}
}
.change {
	display: flex;
	flex-wrap: wrap;
	> p {
		width: 50%;
		font-size: 14px;
		display: flex;
		align-items: center;
		color: #333;
		/deep/.el-input__inner {
			width: inherit;
			background: none;
			height: 32px;
			// line-height: 32px;
			color: #333;
			border: 1px solid rgba(0, 0, 0, 0.1);
			padding: 0 25px;
		}
		/deep/.el-input__icon {
			line-height: 32px;
		}
		.userselect {
			flex: 1;
		}

		> span {
			display: block;
			width: 120px;
			text-align: right;
			padding-right: 15px;
		}
		> input {
			width: inherit;
			flex: 1;
			height: 32px;
			border-radius: 3px;
			border: 1px solid rgba(0, 0, 0, 0.1);
			padding-left: 10px;
			color: #333;
		}
	}
}
</style>
